//引入userModel
const userModel = require("../models/userModel");
//引入加密模块
const {createHash} = require("crypto")

module.exports={
    //根据用户和密码查询用户
    async getuserbyUserNameAndPwd(username,pwd){
       //console.log(username,pwd)
      return await userModel.findOne({
        name:username,
        password:createHash("sha256")
                  .update(pwd)
                   .digest("hex")          
    }).exec();
   },
   //注册用户
   async insertUser(username,pwd){
    return await userModel.create({
        name:username,
        password:createHash("sha256")
                .update(pwd)
                .digest("hex")
    }) 
   },
   //根据用户名查询
   async getUserbyUserName(name){
      return await userModel.findOne({name}).exec()
   }
}

insertUser("z3",111)

